<template>
    <!-- 社群群成员列表 -->
    <div id="as-member-list">
        <top-nav :title="title" /> 
        <div class="top-explain">
            <span>{{topText}}</span>
            <a @click="toBus">创建我的业务名片</a>
        </div>
        <list 
        :height="listHeight" 
        :listData="list" 
        :pageBasicData="pageBasicData"
        @setPageBasicData="setPageBasicData" 
        @setPariseCount="setPariseCount"
        @addList="addList" />
    </div>
</template>

<script>
// 自定义组件
import TopNav from "_components/project/common/TopNav"
import List from "_components/project/AsMemberList/List"

// 自定义方法
import { checkCacheaIsPageData } from "_projectFn/check"
import { enterUserSet } from "_projectFn/page"
import { returnTime } from "_commonFn/time"
import { checkDataEqualVal } from "_commonFn/check"
import { defaultShare } from "_commonFn/share"

export default {
    name: 'AsMemberList',
    data() {
        return {
            title: '群成员',
            list: [],
            apiData: [],
            topText: '',
            pageBasicData: {
                seted: 0,
                memberCout: 0,
                committeeCount: 0,
                busCount: 0,
                userDayTs: '', // 群员每天投诉次数
                appointDayTs: '', // 群委每天投诉次数
                userDayTsThis: '', // 群员每天投诉同一群员次数
                tsCount: '', // 当前用户当天投诉次数
                groupLordCount: '', // 群主数量
                lockView: '', // 当前登录用户是否受限(1:是,0:否)
                ViewGroupUserItemPage: '',
                bindWechat: '', // 当前登录用户是否绑定微信(1:是,0：否)
            },
            listHeight: (window.innerHeight || document.documentElement.clientHeight) - 40 - 30,
        }
    },
    methods: {
        // 进入设置业务信息页面
        toBus() {
            const url = process.env.IS_L0CAL ? location.href.split('#')[0] : `../user-accountManagement.html?option=business`
            enterUserSet('business', url)
        },
        // 设置点赞数量
        setPariseCount({
            userId, count
        }) {
            if (userId && count >= 0) {
                const list = [...this.list]
                list.forEach(item => {
                    if (item.userId == userId) {
                        item.praise = count
                    }
                })
                this.list = list
                // console.log('this.list', this.list)
            }
        },
        addList(list) {
            const arr = this.list
            list.forEach(item => {
                arr.push({
                    userId: item.UserId || '', // string	用户编号
                    nickName: item.NickName, // string	昵称
                    sex: item.Sex == 2 ? 0 : item.Sex == 1 ? 1 : 2, // int	性别(1:男，1：女，2：未知)
                    headImg: item.HeadImg, // string	用户头像
                    userNumber: item.UserNumber, // string	群员号
                    praise: item.Praise, // int	点赞数量
                    gustBook: item.GustBook, // int	留言数量
                    isTs: item.IsTs, // int	当前登录用户是否已投诉该群员(1:是,0:否)
                    reserved: item.Reserved, // string	预留信息
                    userType: Number(item.UserType), // int	群员身份类型(0:普通群员,1:群主，2：普通群委,3:纪律群委,4:活动群委,5:学习群委,6:首席群委)
                    tsCountThis: item.TsCountThis, // int	当前用户当天投诉该用户次数
                    userLevel: item.UserLevel, // int	用户级别(0：普通用户,1:高级用户,2:资深用户,3:超级用户)
                    offer: item.Offer, // float	贡献分
                    area: item.Area, // string	业务名片->所在地区
                    signature: item.Signature, // string	用户签名
                    joinInfo: item.JoinInfo, // string	入群介绍
                    joinTime: item.JoinTime, // long	入群时间截
                    isBusiness: item.IsBusiness, // int	是否填写了业务名片(1:是,0:否)
                    isPartner: item.IsPartner, // int	是否设置了找合作伙伴(1:是,0:否)
                    isRestricted: item.IsRestricted, // int	是否受限(1:是,0:否)
                    company: item.Company, // string	企业
                    yourSelf: item.YourSelf, // string	介绍
                    supply: item.Supply, // string	供应
                    demand: item.Demand, // string	需求
                    joinTimeText: returnTime({timestamp: item.JoinTime})
                })
            })
        },
        setPageBasicData(data) {
            console.log('setPageBasicData')
            this.pageBasicData.memberCout = data.UserCount || 0
            this.pageBasicData.committeeCount = data.AppiontCount || 0
            this.pageBasicData.busCount = data.BusinessCount || 0
            this.pageBasicData.userDayTs = data.UserDayTs || 0 // 群员每天投诉次数
            this.pageBasicData.appointDayTs = data.AppointDayTs || 0 // 群委每天投诉次数
            this.pageBasicData.userDayTsThis = data.UserDayTsThis || 0 // 群员每天投诉同一群员次数
            this.pageBasicData.tsCount = data.TsCount || 0 // 当前用户当天投诉次数
            this.pageBasicData.groupLordCount = data.GroupLordCount || 0 // 群主数量
            this.pageBasicData.lockView = data.LockView || 0 // 当前登录用户是否受限(1:是,0:否)
            this.pageBasicData.viewGroupUserItemPage = data.ViewGroupUserItemPage || 0
            // this.viewGroupUserItemPage = data.ViewGroupUserItemPage || 0
            this.pageBasicData.bindWechat = data.BindWx || 0 // 当前登录用户是否绑定微信(1:是,0：否)
            this.topText = `群成员${this.pageBasicData.memberCout}人,群委${this.pageBasicData.committeeCount}人,有名片业务人员${this.pageBasicData.busCount}人`
        },
        setPageBasiced() {
            if (this.pageBasicData.seted === 0) {
                this.pageBasicData.seted = 1
            }
        },
        // 设置分享
        setShare() {
            defaultShare({title: this.title})
        }
    },
    activated() {
        const that = this
        checkDataEqualVal({
            data: that.$store.getters,
            key: 'getWechatStatus',
            val: ['success', 'fail'],
            callback(val) {
                if (val === 'success') that.setShare()
            }
        })
        document.getElementById('as-member-list-all').scrollTop = this.$route.meta.listScrollTop
    },
	beforeRouteLeave (to, from, next) {
		from.meta.listScrollTop = document.getElementById('as-member-list-all').scrollTop
		next()
	},
    components: {
        TopNav,
        List,
    }
}
</script>

<style lang="scss" scoped>
.top-explain {
    height: 30px;
    width: 100%;
    background: #f2f2f2;
    color: #999999;
    font-size: 12px;
    padding: 0 15px;
    display: -webkit-flex;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
</style>